package com.dm.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dm.manage.entity.Student;
import com.dm.manage.mapper.StudentMapper;
import com.dm.manage.service.StudentService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
@RequiredArgsConstructor
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {
    @Override
    public Page<Student> listPages(Integer pageNum, Integer pageSize) {
        Page<Student> page = new Page<>(pageNum, pageSize);
        // 使用QueryWrapper明确指定查询条件，避免自动生成有歧义的SQL
        QueryWrapper<Student> wrapper = new QueryWrapper<>();
        // 指定查询字段，避免使用TMP.*形式
        wrapper.select("id", "name", "age", "gender", "major");
        // 按ID升序排列，确保分页结果稳定
        wrapper.orderByAsc("id");
        return this.page(page, wrapper);
    }
}